import {downloadFileName} from "@/sever/utils";

export const  fileType = {
    data(){
        return{
            wordList:['doc','docx'],//word-格式校验
            excelList:['xls','xlsx'],//excel-格式校验
            pptList:['pptx','ppt'],//ppt-格式校验
            pdfList:['pdf'],//pdf'-格式校验
            imgList:['BMP','JPG','JPEG','PNG','GIF','gif','png','jpeg','jpg','bmp'],//img-格式校验
            txtList:['txt'],//txt-格式校验
            videoList:['AVI','MOV','QT','ASF','RM','NAVI'],//video-格式校验
            zipList:['RAR','ZIP','ARJ','Z','zip','rar','arj','z'],//zip-格式校验
            audioList:['acm','aif','AIF','AIFC','AIFF','asf','asp','asx','mp3','wma','avi','rm','rmvb','flv','mpg','mov','mkv'],//audio-格式校验
            //文件类型限制
            acceptObj:".doc,.docx,.xls,.xlsx,.pptx,.pdf,.BMP,.JPG,.JPEG,.PNG,.GIF,.txt,.AVI,.MOV,.QT,.ASF,.RM,.NAVI,.acm,.aif,.AIF,.AIFC,.AIFF,.asf,.asp,.asx,.mp3,.wma,.avi,.rm,.rmvb,.flv,.mpg,.mov,.mkv,.RAR,.ZIP,.ARJ,.Z,",
        }
    },
    methods:{
        // 图片大小检查
        beforeAvatarUpload(file) {
            // this.fileType = this.extname(file.name);
            const isLt2M = file.size / 1024 / 1024 < 20;
            if (!isLt2M) {
                this.$Message.error("上传附件不能超过 20MB!");
            }
            return;
        },
        // 下载附件
        download(url,name){
            if(url){
                if(name){
                    downloadFileName(url,name);
                }else{
                    window.open(url);
                }

            }else{
                this.$Message.warning("暂无附件");
            }
        },
        extname(filename) {
            if (!filename || typeof filename != "string") {
                return false;
            }
            let a = filename.split("").reverse().join("");
            let b = a.substring(0, a.search(/\./)).split("").reverse().join("");
            return b;
        },
    }
}
